<template>
  <div class="warp">
    <a-descriptions title="订单信息" bordered :column="2">
      <a-descriptions-item v-for="item in itemList" :label="item.label" :key="item.field">{{
        dataMap[item.field]
      }}</a-descriptions-item>
    </a-descriptions>

    <a-descriptions title="分润信息" bordered :column="2" style="margin-top: 50px">
      <a-descriptions-item v-for="item in accountInfo" :label="item.label" :key="item.field">{{
        accountInfoMap[item.field]
      }}</a-descriptions-item>
    </a-descriptions>
  </div>
</template>

<script>
import { BusinessOrderDetail, orderTypeDict, payModeDict, AccountInfo } from '@/api/order/order'

export default {
  data() {
    return {
      itemList: [
        { label: '订单编号', field: 'orderCode' },
        { label: '订单状态', field: 'orderState' },
        { label: '业务类型', field: 'orderType' },
        { label: '订单来源', field: 'sourceOrgName' },
        { label: '项目归属', field: 'orgName' },
        { label: '订单金额', field: 'totalMoney' },
        { label: '实付金额', field: 'payMoney' },
        { label: '提交时间', field: 'createTime' },
        { label: '支付流水号', field: 'payCode' },
        { label: '支付方式', field: 'payMode' },
        { label: '支付时间', field: 'payTime' },
      ],
      dataMap: {
        orderCode: 1,
        orderState: 2,
        orderType: undefined,
        sourceOrgName: undefined,
        orgName: undefined,
        totalMoney: undefined,
        payMoney: undefined,
        createTime: undefined,
        payCode: undefined,
        payMode: undefined,
        payTime: undefined,
      },

      accountInfo: [
        { label: '分账金额', field: 'amount' },
        { label: '服务费', field: 'service' },
        { label: '供应商', field: 'sourceOrgName' },
        { label: '分销商', field: 'orgName' },
        { label: '分账状态', field: 'settStatus' },
        { label: '分账比例', field: 'percentStr' },
      ],
      accountInfoMap: {
        amount: 0,
        service: 0,
        orgName: undefined,
        sourceOrgName: undefined,
        settStatus: 0,
        percentStr: undefined,
      }
    }
  },
  methods: {
    async getOrderDetail() {
      let res = await BusinessOrderDetail(this.$route.query.orderCode)
      let data = res.data || {}
      Object.keys(this.dataMap).forEach((k) => {
        if (k === 'orderState') {
          this.dataMap[k] = this.Dict.getDictItem(this.Dict.getLocal('orderStateDict'), data[k]).dictLabel
        } else if (k === 'orderType') {
          this.dataMap[k] = (orderTypeDict.find((v) => v.value == data[k]) || {}).label
        } else if (k === 'totalMoney' || k === 'payMoney') {
          this.dataMap[k] = '￥' + data[k]
        } else if (k === 'payMode') {
          this.dataMap[k] = (payModeDict.find((v) => v.value == data[k]) || {}).label
        } else {
          this.dataMap[k] = data[k]
        }
      })
      this.accountInfoMap.orgName = data.orgName
      this.accountInfoMap.sourceOrgName = data.sourceOrgName
    },
    async getAccountInfo() {
      let res = await AccountInfo(this.$route.query.orderCode)
      let data = res.data || {}
      Object.keys(this.accountInfoMap).forEach((k) => {
        if (k === 'amount' || k === 'service') {
          this.accountInfoMap[k] = '￥' + data[k]
        } else if (k === 'settStatus') {
          this.accountInfoMap[k] = data[k] ? this.Dict.getDictItem(this.Dict.getLocal('orderSettStatusDict'), data[k]).dictLabel : "";
        } else {
          this.accountInfoMap[k] = data[k]
        }
      })
    },
  },
  async created() {
    await this.getAccountInfo()
    this.getOrderDetail()
  },
}
</script>

<style scoped>
.warp {
  background-color: #fff;
  padding: 20px;
}
</style>